package com.esun.rabbit2.viewer.mainact.lotteryhallact;

import com.esun.config.Config;
import com.esun.ui.R;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * @Title: AboutAct.java
 * @Package com.esun.rabbit2.viewer.mainact.lotteryhallact
 * @Description: (玩法介绍Activity)
 * @author City jiangsy@500wan.com
 * @date 2011-5-26 上午10:43:00 copy right 深圳市易讯天空网络技术有限公司
 */
public class HelpAct extends Activity implements OnClickListener {
	/** Called when the activity is first created. */
	private ImageButton btnCancel;
	private WebView wvContent;
	private TextView tvTitle;
	private RelativeLayout relativeProgress;
	private FrameLayout frameTitle;
	private Bundle bundleHelpAct;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hlpe_act);
		initUI();
	}

	private void initUI() {
		// TODO Auto-generated method stub
		btnCancel = (ImageButton) findViewById(R.id.helpact_btn_back);
		btnCancel.setOnClickListener(this);
		bundleHelpAct = this.getIntent().getExtras();

		relativeProgress = (RelativeLayout) findViewById(R.id.helpact_relative_progress);
		tvTitle = (TextView) findViewById(R.id.helpact_tv_title);
		tvTitle.setText(bundleHelpAct.getString("title"));

		frameTitle = (FrameLayout) findViewById(R.id.helpact_frame_title);
		if (bundleHelpAct.getString("havetitle").equals(Config.NUM0)) {
			frameTitle.setVisibility(View.GONE);
		} else {
			frameTitle.setVisibility(View.VISIBLE);
		}

		wvContent = (WebView) findViewById(R.id.helpact_webbiew);
		wvContent.setWebViewClient(new WebViewClient() {

			@Override
			public void onPageFinished(WebView view, String url) {
				// TODO Auto-generated method stub
				super.onPageFinished(view, url);
				relativeProgress.setVisibility(View.GONE);
				wvContent.setVisibility(View.VISIBLE);
			}

			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				// TODO Auto-generated method stub
				super.onPageStarted(view, url, favicon);
				relativeProgress.setVisibility(View.VISIBLE);
			}

		});
		wvContent.loadUrl(bundleHelpAct.getString("url"));

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.helpact_btn_back:
			HelpAct.this.finish();
			break;

		default:
			break;
		}

	}

	// 将menu键点击事件返回给父activity处理
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
			Activity parent = getParent();
			if (parent != null) {
				parent.onKeyDown(keyCode, event);
				return true;
			}
		}
		return super.onKeyDown(keyCode, event);
	}
	
	@Override
	public boolean onTrackballEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		Activity parent = getParent();
			if (parent != null) {
				parent.onTrackballEvent(event);
				return true;
			}
		return false;
	}
}
